<?php
include('../../__global.php');
include(SERVER_ROOT_PATH.'/include/config/ml_guang_config.php');
class guang_ctg extends ml_controller
{
    private $_order;    //排序
    private $block;    //当前显示的块数
    private $page;    //当前页码
    private $type;    //品类名
    private $ctg_id;
    private $color;
    private $sex;
    private $minPrice;
    private $maxPrice;
    private $filter;
    private $_order_array = array('hot', 'new');

    public function initParam()
    {
        $this->order = $this->input('order', 'G', 'hot');

        $page = (int)$this->input('page' , 'G' , 1);
        $page = $page < 1 ? 1 : $page;
        $page = $page > ML_GUANG_TOTAL_PAGE ? 1 : $page;
        $this->page = $page;
        $this->block = ($page-1)*ML_GUANG_BLOCK;

        $this->type = $this->input('type','G','');
        if(!Tool_string::isUtf8($this->type))
        {
            $this->type = Tool_string::gb2utf($this->type);
        }
        global $ML_CATELOG_REV;
        $this->ctg_id = $ML_CATELOG_REV[$this->type];
        if(!$this->ctg_id)
        {
            $this->redirect(ML_PAGE_GUANG);
        }
        $this->color = $this->input('color');
        $this->sex = $this->input('sex');
        $this->maxPrice = $this->input('maxPrice');
        $this->minPrice = $this->input('minPrice');
        $this->filter = $this->input('filter');
        define('ML_SHOW_GOODS_FRM', 'pb'.$this->block);
    }
    public function checkParam()
    {
        global $ML_COLOR_CSS;
        $this->order = in_array($this->order, $this->_order_array) ? $this->order : 'hot';
        if(!Tool_input::param_base($this->maxPrice, array('type'=>ML_DATATYPE_DIGIT))){
            $this->maxPrice = '';
        }
        if(!Tool_input::param_base($this->minPrice, array('type'=>ML_DATATYPE_DIGIT))){
            $this->minPrice = '';
        }
        
    }
    public function main()
    {
        global $ML_CATELOG;
        global $ML_CATELOG_REV;
        global $ML_COLOR_CSS;

        $page_type = 'ctg_'.$this->order;
        //行为LOG start
        $aTarget = array(
            'ctg' => $this->ctg_id,
            'order' => $this->order,
            'page' => $this->page,
        );
        if(!empty($this->color))
            $aTarget['color'] = $this->color;
        if(!empty($this->sex))
            $aTarget['sex'] = $this->sex;
        if((!empty($this->minPrice)) || (!empty($this->maxPrice))){
            $aTarget['price'] = trim($this->minPrice.'_'.$this->maxPrice, '_');
        }
        ml_tool_actionlog::view_guang($this->__visitor['uid'] , $aTarget);
        //行为LOG end
            
        
        //取数据全在接口进行，本操作只为取页数
        $option = array('sort'=>$this->order,'ctg'=>$this->ctg_id,'tag'=>array($this->filter),'color'=>$this->color,'sex'=>$this->sex,'maxPrice'=>$this->maxPrice,'minPrice'=>$this->minPrice,'block'=>$this->block);        
        $oGuang = new ml_biz_guang();
        $oGuang->check($option);
        $content = $oGuang->main();
        $oPin = new ml_biz_pin_content();
        $tmp = $oPin->output($this->__visitor['uid'], $content['rows'], false);
        $tmp = ml_tool_pinOutput::groupPinByColumn($tmp , 4);
        $data['pins'] = $tmp;



        $data['page_type'] = 'ctg_'.$this->order;
        $data['ctg_id'] = $this->ctg_id;

        //顶部 tag列表数据
        $data['ctgtag'] = ml_factory::load_standard_conf('op_guangHotTag');

        //2级筛选的标签
        $tag2tag = ml_tool_getdata::mlJsonData('tag2tag','tagdata');
        $data['tag2tag'] = $tag2tag[$tag_id]['list'];
        $data['righttag'] = ml_tool_tagfilter::righttag($tag_id);
        $data['name'] = $this->type;
        $data['type'] = $this->type;
        $data['minPrice'] = $this->minPrice;
        $data['maxPrice'] = $this->maxPrice;//目前的价格是写死的，以后切到后台
        $data['color'] = $this->color;
        $data['sex'] = $this->sex;
        $data['filter'] = $this->filter;
        $data['order'] = $this->order;
        $data['noh1'] = true;//logo无h1标签
        $data['color_list'] = $ML_COLOR_CSS[$this->type];//目前颜色基于配置的，以后切到后台
        $total_block = ceil($content['total']/ML_GUANG_PAGESIZE);
        $this->set_scope_var('$minPrice' , $this->minPrice);
        $this->set_scope_var('$maxPrice' , $this->maxPrice);
        $this->set_scope_var('$color' , $this->color);
        $this->set_scope_var('$sex' , $this->sex);
        $this->set_scope_var('$filter' , $this->filter);
        $this->set_scope_var('$order' , $this->order);
        $this->set_scope_var('$ctg' , $this->type);

        $this->set_scope_var('$totalPage' , ceil($total_block / ML_GUANG_BLOCK));
        $this->set_scope_var('$currentPage' , $this->page);
        $this->set_scope_var('$segment' , 0);
        $this->set_scope_var('$lastSegment' , $this->block == $total_block - 1 ? true : false);


        $this->set_page_title($this->type." - ".$this->type."最潮单品，".$this->type."女装，".$this->type."搭配");
        $this->page_output('lm::public' , $data);
    }

}
new guang_ctg();
?>